<?php
include 'common/header.html';
include 'common/left.html';
include("common/page.php");
include_once 'module/common/Db.class.php';
use \PFT\Db;
$conf =include 'module/common/db.conf.php';
Db::Conf($conf['remote_1']);
$Db = Db::Connect();

$pageSize=$_REQUEST['pageSize']?$_REQUEST["pageSize"]:10;
$currentPage=$_REQUEST["currentPage"]?$_REQUEST["currentPage"]:1;
$offset=($currentPage-1)*$pageSize;

$sql = <<<SQL
SELECT m.id,m.activity_name,activity_bt,activity_et,buy_limit,
share_page,`status`,s.coupon_id,s.share_type,s.red_pack_money FROM pft_marketing m
LEFT JOIN pft_marketing_sp s ON s.id=m.share_page
WHERE m.fid=? and m.activity_type=3 and m.status in (0,2) ORDER BY id DESC limit $offset,$pageSize
SQL;
//echo $sql;
$stmt = $Db->prepare($sql);
$stmt->execute(array($_SESSION['sid']));
$share_pages = array();
while($row=$stmt->fetch(PDO::FETCH_ASSOC)) {
    $rows[] = $row;
//    if ($row['activity_type']==3 && $row['share_page']>0) {
//        $share_pages[]  = $row['share_page'];
//    }
}
//print_r($rows);
//$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
$activity_typeT  =array(1=>'秒杀',2=>'限量打折',3=>'分享立减');
//分享页面数据
if ($cnt = count($share_pages)) {
    $sql = "SELECT id,title,image_path FROM pft_marketing_sp WHERE id IN("
        .implode(',', $share_pages).") LIMIT $cnt";

    $stmt = $Db->prepare($sql);
    $stmt->execute();
    $share_page_list = array();
    while($row=$stmt->fetch(PDO::FETCH_ASSOC)) {
        $share_page_list[$row['id']] = $row;
    }
}

$sel_count = "SELECT count(*) from pft_marketing where fid=?  and status in (0,2)";
$stmt = $Db->prepare($sel_count);
$stmt->execute(array($_SESSION['sid']));
$count = $stmt->fetchAll(PDO::FETCH_ASSOC);
$count = $count[0]['count(*)'];

?>
<!--<script type="text/javascript" src="http://www.12301.cc/js/plugin/json2.js"></script>-->
<!--[if lt IE 7]><div id="childListWrap" class="lt-ie10 lt-ie9 lt-ie8 lt-ie7 ie6 childListWrap"> <![endif]-->
<!--[if IE 7]><div id="childListWrap" class="lt-ie10 lt-ie9 lt-ie8 ie7 childListWrap"> <![endif]-->
<!--[if IE 8]><div id="childListWrap" class="lt-ie10 lt-ie9 ie8 childListWrap"> <![endif]-->
<!--[if IE 9]><div id="childListWrap" class="lt-ie10 ie9 childListWrap"><![endif]-->
<!--[if gt IE 9]><!--><div id="childListWrap" class="childListWrap"> <!--<![endif]-->
    <link rel="stylesheet" href="http://www.12301.cc/css/common/www.12301.cc.global.css"/>
    <link rel="stylesheet" href="http://www.12301.cc/css/marketing_list.css"/>
    <script src="http://wx.12301.cc/public/js/plugins/qrcode.min.js"></script>
    <script language="javascript" src="http://www.12301.cc/js/jquery-1.8.0.min.js"></script>
    <script src="http://www.12301.cc/wx_public/zclip/jquery.zclip.min.js"></script>
    <link rel="stylesheet" href="css/page.css" media="all" />
    <div class="tipMsg" style="position: fixed; top: 0; left: 50%; width:180px; height: 40px; line-height: 40px; display: none; background: #3DBA3F;text-align: center; color: #FFF; font-size: 16px; margin-left: -90px;">
       
        <p>复制成功</p>
    </div> 
<h3 class="mc_title"><span class="mctit_1"><span class="mctit_2">营销活动列表</span></span></h3></br>
    <input type="hidden" id="lid" value="<?=$_REQUEST['lid']?>" />
    <input type="hidden" name="sort" value='<?=json_encode($sort)?>'/>
    <a id="addChildBtn_a" class="addChildBtn" href="marketing_csp.html?dev=1" target="_blank">创建</a>
    <table id="listTable" class="proTable fixed setStyle">
        <thead id="proTableHead">
            <tr>
                <th class="col_1">活动名称</th>
                <th class="col_2">活动时间</th>
                <th class="col_4">赠送类型</th>
                <th class="col_4">二维码</th>
                <th class="col_5">操作</th>
            </tr>
        </thead>
        <?php if(is_array($rows)):?>
        <?php foreach($rows as $k => $v):?>
             <tbody data-id="<?=$v['share_page']?>">
                <tr class="listBody borderBottom">
                    <td class="col_1 col">
                        <span><?=$v['activity_name']?></span>
                    </td>
                    <td class="col_2 col">
                        <p><span class="colorGray">开始：</span><?=date('Y-m-d H:i:s',$v['activity_bt'])?></p>
                        <p><span class="colorGray">结束：</span><?=date('Y-m-d H:i:s',$v['activity_et'])?></p>
                    </td>
                    <td>
                        <?php if($v['share_type']==1):?>
                            <p>送优惠券</p>
                            <p class="colorGray">(优惠券ID:<?=$v['coupon_id']?>)</p>
                        <?php elseif($v['share_type']==2):?>
                            送现金红包(金额:<?=$v['red_pack_money']?>)
                        <?php endif;?>
                    </td>
                    <td class="qr-code" id="qr_<?=$v['id']?>">
                        <script>
                            var qrcode = new QRCode("qr_<?=$v['id']?>", {
                                text: "http://<?=$_SESSION['saccount']?>.12301.cc/wx/game/share_pages/page_share.html?id=<?=$v['share_page']?>",
                                width: 128,
                                height: 128,
                                colorDark : "#000000",
                                colorLight : "#ffffff",
                                correctLevel : QRCode.CorrectLevel.H
                            });
                        </script>
                    </td>
                    <td class="col_5 col">
                        <a class="do close" href="javascript:;"><i class="cpicon close"></i><i class="cpicon close-hover hover"></i></a>
                    </td>
                </tr>
                <tr>
                    <td style="text-align:left;line-height: 35px;padding-left: 10px; position: relative;" colspan="5">分享地址:
                        <span class="copyLink">http://<?=$_SESSION['saccount']?>.12301.cc/wx/game/share_pages/page_share.html?id=<?=$v['share_page']?></span>
                      <button class="clipLinkBtn copy" >复制链接</button>
                    </td>
                   
                </tr>
                
                </tbody>
            <?php endforeach;?>
        <?php endif;?>
    </table>
     <?if(count($rows)!=0){page($count,$currentPage,$pageSize);}?>
</div>

 
    <script type="text/javascript" src="http://www.12301.cc/js/global/www.12301.cc.global.js"></script>
    <script type="text/javascript" src="http://www.12301.cc/js/marketing/marketing_list.js"></script>
<script>
    $(function(){

        $("#listTable").on("click",".listBody .close",function(e){ //删除
            var target = $(e.currentTarget);
            var result = window.confirm("确定要删除吗");
            if(!result) return false;
            var citem = target.parents("tbody");
            deleteChild(citem.data("id"),citem);
        })

        function deleteChild(id,citem){ 
            //if(!id) return false;
            PFT_GLOBAL.G.Ajax({
                url : "http://www.12301.cc/call/jh_marketing.php",
                type : "POST",
                dataType : "JSON",
                data : {
                    action : "sp_delete",
                    id : id,
                    flag:1
                },
                loading : function(){

                },
                removeLoading : function(){

                }
            },function(code){
                if(code == '200'){
                    citem.remove();
                    PFT_GLOBAL.U.Alert("success",'<p style="width:160px">删除成功</p>',1.5 * 1000);
                }else{
                    PFT_GLOBAL.U.Alert("fail",'<p style="width:160px">删除失败，请稍后重试</p>',1.5 * 1000);
                }
            })
        }
    
        $(".clipLinkBtn").zclip({
            path: "http://www.12301.cc/wx_public/zclip/ZeroClipboard.swf",
           copy: function(){
                return $(this).siblings(".copyLink").text();
            },
           deforeCopy : function(){},
           afterCopy : function(){
                $(".tipMsg").css("display","block");
                $(".tipMsg").fadeOut(1800);
               
          }
        });
    });
</script>
<?php include('common/footer.html')?>